package com.liushuai.phoneguardian.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;

public class CopyFileUtils {
	/**
	 * 拷贝文件到系统的某个目录
	 * 
	 * @param is
	 *            源文件的流
	 * @param destPath
	 *            目标路径
	 * @return
	 */
	public static File copyFile(InputStream is,String destpath){
		
		try {
			File file = new File(destpath);
			FileOutputStream fos = new FileOutputStream(file);
			int len = 0;
			byte[] buffer = new byte[1024];
			while((len=is.read(buffer))!=-1){
				fos.write(buffer, 0, len);
			}
			fos.flush();
			fos.close();
			is.close();
			return file;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
		
		
	}

}
